package com.ruoyi.web.publish.dividend.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.publish.dividend.domain.Dividend;
import com.ruoyi.web.publish.dividend.service.IDividendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分红Controller
 *
 * @author houxuzhong
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/publish/dividend")
public class DividendController extends BaseController
{
    @Autowired
    private IDividendService dividendService;

    /**
     * 查询分红列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Dividend dividend)
    {
        startPage();
        List<Dividend> list = dividendService.selectDividendList(dividend);
        return getDataTable(list);
    }

    /**
     * 查询我的分红列表
     */
    @GetMapping("/myList")
    public TableDataInfo myList(Dividend dividend)
    {
        startPage();
        List<Dividend> list = dividendService.selectMyDividendList(dividend);
        return getDataTable(list);
    }

    /**
     * 导出分红列表
     */
    @Log(title = "分红", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Dividend dividend)
    {
        List<Dividend> list = dividendService.selectDividendList(dividend);
        ExcelUtil<Dividend> util = new ExcelUtil<Dividend>(Dividend.class);
        return util.exportExcel(list, "分红数据");
    }

    /**
     * 获取分红详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dividendService.selectDividendById(id));
    }

    /**
     * 新增分红
     */
    @Log(title = "分红", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dividend dividend)
    {
        return toAjax(dividendService.insertDividend(dividend));
    }

    /**
     * 修改分红
     */
    @Log(title = "分红", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dividend dividend)
    {
        return toAjax(dividendService.updateDividend(dividend));
    }

    /**
     * 删除分红
     */
    @Log(title = "分红", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dividendService.deleteDividendByIds(ids));
    }
}
